import 'package:enjoy_pro_max/pages/home/components/home_list.dart';
import 'package:enjoy_pro_max/pages/home/components/home_nav.dart';
import 'package:enjoy_pro_max/utils/http.dart';
import 'package:enjoy_pro_max/utils/toast.dart';
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    super.initState();
    getNotityData();
  }

  List notifyList = [];
  getNotityData() async {
    final res = await http.get('/announcement');
    setState(() {
      notifyList = res['data'];
      ToastUtil.showSuccess('数据加载成功');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromARGB(255, 228, 231, 242),
      appBar: AppBar(
        title: const Text('享+社区'),
        centerTitle: true,
        backgroundColor: Colors.transparent,
      ),
      body: ListView(
        padding: const EdgeInsets.all(10),
        children: [
          const HomeNav(),
          const SizedBox(
            height: 10,
          ),
          ClipRRect(
            borderRadius: BorderRadius.circular(10),
            child: Image.asset('assets/images/banner@2x.jpg'),
          ),
          HomeList(notifyList: notifyList),
        ],
      ),
    );
  }
}
